package com.wfuhui.book.ui.cart;

import android.widget.CheckBox;
import android.widget.ImageView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.bumptech.glide.Glide;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;
import com.wfuhui.book.R;
import com.wfuhui.book.model.Cart;
import com.wfuhui.book.util.GlideImageLoader;

import java.text.DecimalFormat;
import java.util.List;

public class CartQAdapter extends BaseQuickAdapter <Cart, BaseViewHolder> {

    DecimalFormat format = new DecimalFormat("#.00");

    public CartQAdapter(int layoutResId) {
        super(layoutResId);
    }

    public CartQAdapter(int layoutResId, @Nullable List<Cart> data) {
        super(layoutResId, data);
    }

    @Override
    protected void convert(@NonNull BaseViewHolder baseViewHolder, Cart cart) {

        baseViewHolder.setText(R.id.name,"书本名称："+ cart.getBookName());
        baseViewHolder.setText(R.id.author,"作者名称："+ cart.getAuthor());
        baseViewHolder.setText(R.id.price,"书本价格："+ format.format(cart.getPrice())+"");
        new GlideImageLoader().displayImage(getContext(), cart.getPicUrl(), (ImageView) baseViewHolder.getView(R.id.pic));
        if(cart.isselect){
            ( (CheckBox)   baseViewHolder.getView(R.id.cb)).setChecked(true);
        }else
            ( (CheckBox)   baseViewHolder.getView(R.id.cb)).setChecked(false);
    }
}
